package com.pwx.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pwx.dao.EdocMapper;
import com.pwx.entity.Edoc;
import com.pwx.services.EdocServices;
import com.pwx.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Copyright (C),2021-2022,亚瑟王
 * FileName: EdocServicesImpl
 * Author: saber
 * Date:2022/10/7 10:41
 */
@Service
@Transactional
public class EdocServicesImpl implements EdocServices {
    @Autowired
    private EdocMapper em;

    @Override
    @Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
    public PageInfo<Edoc> getAll(Map<String, String> maps) {
        int pageNum = StringUtil.stringToInt(maps.get("pageNum"));
        PageHelper.startPage(pageNum,2);
        List<Edoc> list = em.findByMap(maps);
        PageInfo<Edoc> info = new PageInfo<>(list);
        return info;
    }


    @Override
    public boolean addEdoc(Edoc edoc) {
        if (edoc!=null){
           return em.addEdoc(edoc);
        }
        return false;
    }

    @Override
    public boolean delEdoc(Integer eId) {
        if (eId!=null&&eId>0) {
            return em.deleteEdoc(eId);
        }
        return false;
    }


    @Override
    public Edoc findEdocByEId(Integer eId) {
        if (eId!=null&&eId>0) {
            return em.findByEId(eId);
        }
        return null;
    }

    @Override
    public boolean updateEdoc(Edoc edoc) {
        if (edoc!=null){
            return em.updateEdoc(edoc);
        }
        return false;
    }
}
